import * as CryptoJS from "crypto-js";
// 加密
export let encrypt = (word: string) => {
  // encrypt(word: string,keyStr: string) {
  // keyStr = keyStr ? keyStr : 'hncdcenterdtclou';
  const key = CryptoJS.enc.Utf8.parse("hncdcenterdtclou");
  const srcs = CryptoJS.enc.Utf8.parse(word);
  const encrypted = CryptoJS.AES.encrypt(srcs, key, {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7,
  });
  return encrypted.toString();
};
// 解密
export let decrypt = (word: string) => {
  // decrypt(word: string,keyStr: string) {
  // keyStr = keyStr ? keyStr : 'hncdcenterdtclou';
  const key = CryptoJS.enc.Utf8.parse("hncdcenterdtclou");
  const decrypt = CryptoJS.AES.decrypt(word, key, {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7,
  });
  return CryptoJS.enc.Utf8.stringify(decrypt).toString();
};
// 加密
export function encryptAES256(data: string, secretKey: string): string {
  return CryptoJS.AES.encrypt(data, secretKey, {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7,
  }).toString();
}

// 解密
export function decryptAES256(
  encryptedData: string,
  secretKey: string
): string {
  const bytes = CryptoJS.AES.decrypt(encryptedData, secretKey);
  return bytes.toString(CryptoJS.enc.Utf8);
}

